﻿using System.Collections;
using UnityEngine;
using YooAsset;
namespace LitFramework
{
    public class AssetState_UpdateVersion : IState
    {
        public StateMechine Master { get; set; }
        private ResourcePackage package;

        public void OnEnter(params object[] values)
        {
            GameManager.Instance.InitState = "HotUpdate UpdateVersion...";
            GameManager.Instance.InitProgress = 0;

            package = values[0] as ResourcePackage;
            GameManager.Instance.StartCoroutine(UpdatePackageVersion());
        }

        public void OnExit()
        {

        }

        public void OnUpdate()
        {

        }

        private IEnumerator UpdatePackageVersion()
        {
            yield return new WaitForEndOfFrame();

            var operation = package.UpdatePackageVersionAsync();
            yield return operation;

            if (operation.Status != EOperationStatus.Succeed)
            {
                TipPanel.ShowTip(operation.Error, "好的", null);
            }
            else
            {
                Master.TurnToState<AssetState_UpdateManifest>(package, operation.PackageVersion);
            }
        }
    }
}